function login(){
    // var username = document.getElementById('username')
    // var pwd = document.getElementById('pwd')
    let i
    for(i = 0; i<5; i++){
        // var username = document.getElementById('username')
        // var pwd = document.getElementById('pwd')
        let username = prompt('username')
        let pwd = prompt('pwd')
        if( username ==  'admin' && pwd ==  123456 ){
            alert('Login succeed')
            break;
        }else{
            let times = 4 - i
            alert('You have ' + times + ' times')
        }
        
    }
}


function login2() {
    
    let username = document.getElementById('username').value
    let phoneNumber = document.getElementById("phonenumber").value;
    
    let usernameReg = /^\w{6,12}$/
    let phoneReg = /^1[3-9]\d{9}$/

    // 验证手机号是否符合格式
    if(usernameReg.test(username) && phoneReg.test(phoneNumber)){
        alert("Login succeed!")
    }else if(!usernameReg.test(username) && phoneReg.test(phoneNumber)){
        // alert("Wrong username!")
        document.getElementsByTagName('span')[0].innerHTML("Wrong username!")
    }else if(!phoneReg.test(phoneNumber && usernameReg.test(username))){
        // alert("Wrong phonenumber!")
        document.getElementsByTagName('span')[1].innerHTML("Wrong phonenumber!")
    }else{
        alert("Go out!")
    }
}

// document.getElementById('username').onblur = function(){
//     var reg = /^\w{6,12}$/
//     var name = document.getElementById('username').value
//     if(reg.test(name)){
//         document.getElementsByTagName('span')[0].innerHTML("Wrong user!")
//     }else{
//         alert("用户名不合法")
//     }
// }

